import axios from 'axios'
import {ElMessage} from "element-plus";
import useUserStore from "@/store/modules/user";

let request = axios.create({
    baseURL: import.meta.env.VITE_APP_BASE_API,
    timeout: 5000
})

request.interceptors.request.use((config)=>{
    const userStore = useUserStore()
    if(userStore.token){
        config.headers.token = userStore.token
    }
    return config
})

request.interceptors.response.use(res=>{
    return res.data;
},error => {
    ElMessage({
        type: 'error',
        message: error.response.message
    })
    return Promise.reject(error)
})

export default request;
